package top.bug.blog.entity.vo.user;

import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import top.bug.blog.common.BasePO;
import top.bug.blog.entity.po.User;
import top.bug.blog.utils.DesensitizationUtil;

/**
 * @author <a href="https://github.com/jiusi66">九思.</a>
 * @email 10837907@qq.com
 * @from <a href="https://www.52bug.top">递归茶馆-www.52bug.top</a>
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel("脱敏用户信息视图")
public class SafeUserVO extends BasePO {
    @ApiModelProperty("昵称")
    private String nickname;

    @ApiModelProperty("用户名")
    private String username;

    @ApiModelProperty("手机号")
    private String phone;

    @ApiModelProperty("邮箱")
    private String email;

    @ApiModelProperty("主页地址")
    private String homeUrl;

    @ApiModelProperty("个人签名")
    private String sign;

    @ApiModelProperty("简介标签")
    private String tagInfo;

    @ApiModelProperty("头像地址")
    private String avatarUrl;

    @ApiModelProperty("用户状态")
    private String status;

    private SafeUserVO() {
    }

    /**
     * 建造器类
     */
    public static class Builder {
        private final SafeUserVO target = new SafeUserVO();

        public Builder from(User user) {
            BeanUtil.copyProperties(user, target);
            return this;
        }

        public Builder desensitizePhone() {
            target.phone = DesensitizationUtil.desensitizePhone(target.phone);
            return this;
        }

        public Builder desensitizeEmail() {
            target.email = DesensitizationUtil.desensitizeEmail(target.email);
            return this;
        }

        public SafeUserVO build() {
            return target;
        }
    }
}